package it.polimi.meteocal.ejb.eventmanagement;


import it.polimi.meteocal.ejb.usermanagement.User;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;  
import javax.persistence.Temporal;

/**
 * Entity implementation class for Entity: ProdottoBaseEntity
 *
 */
@Entity
@Table(name="EVENT")
@NamedQueries({
	@NamedQuery(name=Event.FIND_ALL,
				query="SELECT p FROM Event p"),
	@NamedQuery(name=Event.findByUser,
				query="SELECT e FROM Event e WHERE e.user.email = :email"),
	@NamedQuery(name=Event.myTomorrowEvents,
				query="SELECT e FROM Event e WHERE e.user.email = :email AND e.begin BETWEEN :todayDate and :tomorrowDate")

})


public class Event implements Serializable {

	public Event() {
		super();
	}

	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Event.findAll";
	public static final String findByUser = "Event.findByUser";
	public static final String myTomorrowEvents = "Event.myTomorrowEvents";

	@Id
	@GeneratedValue (strategy=GenerationType.IDENTITY)
	private int eventid;
	
	private String name;  
	
	private String description;  
	
	private String place;  

	private String insideOutside;  
	
	@Temporal(javax.persistence.TemporalType.TIMESTAMP)
	private Date begin;
	
	@Temporal(javax.persistence.TemporalType.TIMESTAMP)
	private Date end;
	
	@ManyToOne
	@JoinTable(name = "ehasUser",
		inverseJoinColumns={@JoinColumn(name="userEmail",referencedColumnName="email")}, joinColumns={@JoinColumn(name="eventid", referencedColumnName="eventid")})
	private User user;
	
	public Event(EventDTO nuovoPB){
        this.eventid			= nuovoPB.getEventid();
        this.name				= nuovoPB.getName();
        this.description		= nuovoPB.getDescription();
        this.place				= nuovoPB.getPlace();
        this.insideOutside		= nuovoPB.getInsideOutside();
        this.begin				= nuovoPB.getBegin();
        this.end				= nuovoPB.getEnd();
    }
	

	public int getEventid() {
		return eventid;
	}



	public void setEventid(int eventid) {
		this.eventid = eventid;
	}



	public String getName() {
		return name;
	}



	public void setName(String name) {
		this.name = name;
	}



	public String getDescription() {
		return description;
	}



	public void setDescription(String description) {
		this.description = description;
	}



	public String getPlace() {
		return place;
	}



	public void setPlace(String place) {
		this.place = place;
	}



	public String getInsideOutside() {
		return insideOutside;
	}



	public void setInsideOutside(String insideOutside) {
		this.insideOutside = insideOutside;
	}



	public Date getBegin() {
		return begin;
	}



	public void setBegin(Date begin) {
		this.begin = begin;
	}



	public Date getEnd() {
		return end;
	}



	public void setEnd(Date end) {
		this.end = end;
	}



	public User getUser() {
		return user;
	}


	public void setUser(User user) {
		this.user = user;
	}


	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public static String getFindAll() {
		return FIND_ALL;
	}

}

